<?php
     header('content-type:text/html;charset=utf-8;');
    
    $name = $_POST['un'];
    $pw = $_POST['pw'];

$link = mysqli_connect('127.0.0.1','root','root','jd');
$sql = "SELECT * FROM `userinfo` WHERE `username`='$name'";
$res = mysqli_query($link,$sql);
$arr = mysqli_fetch_assoc($res);
if($arr){
    echo '{"code":0}';
}else{
    $sql = "INSERT INTO `userinfo` VALUES (null,'$name','$pw')";
    $res = mysqli_query($link,$sql);
    if($res){
        echo '{"code":1}';
        setcookie('name',$name,7*24*60*60+time());
    }else{
        echo '{"code":0}';
    }
}
?>